package Tree;
//给你一个二叉树的根节点 root ， 检查它是否轴对称。
public class item101 {
}
class Solution101 {
    public static boolean isSymmetric(TreeNode root) {
// 思路：直接从根节点分开，就是两颗子树，然后对着两棵树进行比较
        boolean flag = false;
        if(root==null) return true;

        flag = isSame(root.left,root.right);
        return flag;
    }

    private static boolean isSame(TreeNode left, TreeNode right) {
        if((left==null&&right!=null)||(left!=null&&right==null))
            return false;
        if(left==null&&right==null) return true;
//        if((left.left==null&&right.right!=null)||(left.left!=null&&right==null))
//            return false;
//        if((left.right==null&&right.left!=null)||(left.right!=null&&right.left!=null))
//            return false;
       if(left.val!= right.val) return false;
        boolean flag1 = isSame(left.left, right.right);
        boolean flag2 = isSame(left.right,right.left);
        return flag1&&flag2;


    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2= new TreeNode(2);
        TreeNode node3= new TreeNode(4);
        TreeNode node4= new TreeNode(4);
        root.left = node1;
        root.right = node2;
        node1.right = node3;
        node2.right = node4;
        isSymmetric(root);
    }
}